/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.reviewtemplate.dao;

import com.nus.dataaccess.dao.base.dao.BaseDao;
import com.nus.dataaccess.dao.reviewtemplate.ReviewTemplate;
import java.util.List;
import java.util.Map;
import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;

/**
 *
 * @author robin.foe
 */
public class ReviewTemplateDao extends BaseDao<ReviewTemplate>{

    private static ReviewTemplateDao instance;
    public static ReviewTemplateDao getInstance() {
        if (null == instance) {
            instance = new ReviewTemplateDao();
        }
        return instance;
    }
    private ReviewTemplateDao(){}
    
    
    @Override
    protected Class getReferenceClass() {return ReviewTemplate.class;}
    
    
    public int getTotalCount(Map<String, String> filters){
        Criteria crit = super.createCriteria();
        crit.setProjection(Projections.rowCount()); 
        return (crit.list().isEmpty()) ? 0 :  ((Long)crit.list().get(0)).intValue();
    }
    public List<ReviewTemplate> paginate(int first, int pageSize, String sortField, boolean ascending, Map<String, String> filters){
        Criteria crit = super.createCriteria();
        
        crit.setFirstResult(first);
        crit.setMaxResults(pageSize);
        return crit.list();
    }
    
}
